package com.xia.ndk08_as_code;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private final static String TAG = MainActivity.class.getSimpleName();

    private Button button01,button02;

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button01 = findViewById(R.id.button01);
        button02 = findViewById(R.id.button02);
        button01.setOnClickListener(this);
        button02.setOnClickListener(this);

    }

    public native void addTest01(int number, String text, int[] intArray, String[] stringArray);

    public native void putStudent(Student student);

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button01:
                test01();
                break;

            case R.id.button02:
                test02();
                break;
            default:
                break;
        }
    }

    private void test01() {
        int[] ints = {1, 2, 3, 4, 5};
        String[] strings = {"徐凤年", "老黄", "李淳罡"};
        addTest01(1991, "昊天", ints, strings);
        for (int anInt : ints) {
            Log.d(TAG, "java int value :" + anInt);
        }
    }

    private void test02(){
        Student student=new Student();
        student.setAge(80);
        student.setName("雄霸");
        putStudent(student);
    }
}
